Dr. Wasilios Hariskos
## [1] 2 3 4 1
## [1] "Anton" "Anton" "Berta" "Berta"
klausuren_faktor <- factor(x = c("Mathe", "Statistik", "Mathe", "Statistik"))
print(klausuren_faktor)## [1] Mathe Statistik Mathe Statistik
## Levels: Mathe Statistik
klausur_daten <- data.frame(Name = namen_vektor,
Klausur = klausuren_faktor,
Note = noten_vektor)
print(klausur_daten)## Name Klausur Note
## 1 Anton Mathe 2
## 2 Anton Statistik 3
## 3 Berta Mathe 4
## 4 Berta Statistik 1
matrix() und Listen list()+ - * / ^== != < >=! & | xor()if (condition){Do something}if (condition) else {Do something}if (condition) ifelse (condition) {Do something} else {Do something}for (variable in sequence){Do something}while (condition){Do something}function_name <- function(var){Do something; return(new_variable)}## # A tibble: 1,704 x 6
## country continent year lifeExp pop gdpPercap
## <fct> <fct> <int> <dbl> <int> <dbl>
## 1 Afghanistan Asia 1952 28.8 8425333 779.
## 2 Afghanistan Asia 1957 30.3 9240934 821.
## 3 Afghanistan Asia 1962 32.0 10267083 853.
## 4 Afghanistan Asia 1967 34.0 11537966 836.
## 5 Afghanistan Asia 1972 36.1 13079460 740.
## 6 Afghanistan Asia 1977 38.4 14880372 786.
## 7 Afghanistan Asia 1982 39.9 12881816 978.
## 8 Afghanistan Asia 1987 40.8 13867957 852.
## 9 Afghanistan Asia 1992 41.7 16317921 649.
## 10 Afghanistan Asia 1997 41.8 22227415 635.
## # ... with 1,694 more rows
dplyrmutate() fügt eine Variable als Spalte hinzu oder ersetzt eine bestehende Variableselect() wählt eine Variable ausfilter() filtert Beobachtungen (Zeilen) anhand von Kriteriensummarize() erstellt numerische Zusammenfassungenarrange() sortiert den Datensatz anhand einer Variablegroup_by() erlaubt Daten nach Gruppen zu manipulierenvignette("dplyr") durchlesengapminder %>%
filter(year %in% c(1952, 2007)) %>%
group_by(continent, year) %>%
summarize(avgLifeExp = mean(lifeExp))## # A tibble: 10 x 3
## # Groups: continent [5]
## continent year avgLifeExp
## <fct> <int> <dbl>
## 1 Africa 1952 39.1
## 2 Africa 2007 54.8
## 3 Americas 1952 53.3
## 4 Americas 2007 73.6
## 5 Asia 1952 46.3
## 6 Asia 2007 70.7
## 7 Europe 1952 64.4
## 8 Europe 2007 77.6
## 9 Oceania 1952 69.3
## 10 Oceania 2007 80.7